local skinlist = {}

--将传入的特殊字符串分割成正常的表
---@param input string @ 需要分割的字符串
---@param delimiter? string @ 分割符
skinlist.split = function(input, delimiter)
    if not delimiter then
        delimiter = " "
    end
    input = tostring(input)
    delimiter = tostring(delimiter)
    if (delimiter == "") then return false end
    local pos, arr = 0, {}
    for st, sp in function() return string.find(input, delimiter, pos, true) end do
        table.insert(arr, string.sub(input, pos, st - 1))
        pos = sp + 1
    end
    table.insert(arr, string.sub(input, pos))
    return arr
end

---@param extension Package
skinlist.normalAddSkins = function (extension, _table)
    local general = _table.name  --武将名字
    local skinname = _table.skinname  --皮肤列表，输入一个表，表中按顺序包含所有皮肤的名字
    local kingdom = _table.kingdom or "qun"  --武将所属势力，默认群
    local gender = _table.gender | General.Female   --武将性别
    local translation = _table.translation   --武将名字的翻译
    local blacklist = _table.blacklist
    local blacklistKingdom = _table.blacklistKingdom

    local content = { {enabled_generals = {}, skins = {}} } ---@type SkinPackageContent
    content[1].enabled_generals = {general}

    local prefixes = {"ex__", "ol__", "ty__", "mobile__", "ol_ex__", "ty_ex__", "m_ex__", "ol_js__", "olz__", "ty_heg__", "ty_sp__", "os__", "os_heg__", "os_ex__", "zq__heg", "jy__heg", "js__", "ld__"}
    for _, prefix in ipairs(prefixes) do
        table.insertIfNeed(content[1].enabled_generals, prefix .. general)
    end

    for i = 1, #skinname do
        local total_name = "skin_"..general..tostring(i).."__"..general
        if type(_table.extra) == "table" then
            local special_prefix = _table.extra[2] or kingdom
            local head = special_prefix.."_"..general
            total_name = "skin_"..head..tostring(i).."__"..general
        end
        table.insertIfNeed(content[1].skins, total_name)
        Fk:loadTranslationTable{
            [total_name] = skinname[i]
        }
    end

    extension:addSkinPackage{
        path = "/image/generals",
        content = content
    }
end

return skinlist